/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
/* Generated By:JavaCC: Do not edit this line. SenseBodyParser.java */
                               // Robocup Message Parser
package robocup.parser9;

import robocup.component.infotypes.SenseBodyInfo;
import robocup.component.infotypes.Info;
import java.io.StringReader;
import robocup.component.actions.Action;
import robocup.component.ControllerNumbers;
import robocup.component.ControllerNumbers.VIEW_QUALITY;
import robocup.component.ControllerNumbers.VIEW_ANGLE;
import robocup.component.ControllerNumbers.TEAM;

import robocup.component.AbstractAgent;

/**
 * The Parser for SenseBody-Infos. This class is created by the
 * javacc parser generator. Therefore do not change this class directly,
 * but change the SenseBodyParser.jj and regenerate the code afterwards.
 */
public class SenseBodyParser implements SenseBodyParserConstants {

        /**
	 * The oject, which is returned by the parser. For performance reasons,
	 * always the same object is used, only the values change.
	 */
        SenseBodyInfo sbi = new SenseBodyInfo();
        AbstractAgent rc = null;

        /**
	 * Creates a new instance of the parser.
	 * @param - StringReader - reader for accessing strings
	 * @param - AbstractAgent - the agent object containing this parser
	 */
        public SenseBodyParser(StringReader str, AbstractAgent rc) {
                this(str);
                this.rc = rc;

        }

        /**
	 * Method that parses the sense-body message.
	 */
    public Info parseSenseBody (String cmd)
        throws ParseException{
      ReInit(new StringReader(cmd));

      try {
        startSenseBodyCommand();
      } catch (ParseException e) {
        System.out.println("Exception during Parsing with Command:");
        System.out.println("  " + cmd +"\r\n"+ e);
      }
      return sbi;
    }

  final public void startSenseBodyCommand() throws ParseException {
  Token cycle=null; Token viewModeQual=null; Token viewModeAngle=null;
  Token stamina=null; Token effort=null; Token speed=null; Token speedDir=null;
  Token headAngle=null; Token kick=null; Token dash=null; Token turn=null;
  Token say=null; Token turnNeck=null; Token cat=null; Token move=null;
  Token changeView=null; Token armMoveable=null; Token armExpires=null;
  Token armDist=null; Token armDir=null; Token armCount=null;
  Token focusTeam=null; Token focusNum; Token focusCount=null;
  Token tackleExpires=null; Token tackleCount=null;
  int iFocusNumber = -1;
    cycle = jj_consume_token(NUM);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(VIEW_MODE);
    jj_consume_token(SEP);
    switch (jj_nt.kind) {
    case HIGH:
      viewModeQual = jj_consume_token(HIGH);
      break;
    case LOW:
      viewModeQual = jj_consume_token(LOW);
      break;
    default:
      jj_la1[0] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    jj_consume_token(SEP);
    switch (jj_nt.kind) {
    case WIDE:
      viewModeAngle = jj_consume_token(WIDE);
      break;
    case NARROW:
      viewModeAngle = jj_consume_token(NARROW);
      break;
    case NORMAL:
      viewModeAngle = jj_consume_token(NORMAL);
      break;
    default:
      jj_la1[1] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(STAMINA);
    jj_consume_token(SEP);
    stamina = jj_consume_token(NUM);
    jj_consume_token(SEP);
    effort = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(SPEED);
    jj_consume_token(SEP);
    speed = jj_consume_token(NUM);
    jj_consume_token(SEP);
    speedDir = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(HEAD_ANGLE);
    jj_consume_token(SEP);
    headAngle = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(KICK);
    jj_consume_token(SEP);
    kick = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(DASH);
    jj_consume_token(SEP);
    dash = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(TURN);
    jj_consume_token(SEP);
    turn = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(SAY);
    jj_consume_token(SEP);
    say = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(TURN_NECK);
    jj_consume_token(SEP);
    turnNeck = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(CATCH);
    jj_consume_token(SEP);
    cat = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(MOVE);
    jj_consume_token(SEP);
    move = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(CHANGE_VIEW);
    jj_consume_token(SEP);
    changeView = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(ARM);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(MOVEABLE);
    jj_consume_token(SEP);
    armMoveable = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(EXPIRES);
    jj_consume_token(SEP);
    armExpires = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(TARGET);
    jj_consume_token(SEP);
    armDist = jj_consume_token(NUM);
    jj_consume_token(SEP);
    armDir = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(COUNT);
    jj_consume_token(SEP);
    armCount = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(FOCUS);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(TARGET);
    jj_consume_token(SEP);
    focusTeam = jj_consume_token(TEAM);
    switch (jj_nt.kind) {
    case SEP:
      jj_consume_token(SEP);
      focusNum = jj_consume_token(NUM);
                                                                        iFocusNumber=Integer.parseInt(focusNum.image);
      break;
    default:
      jj_la1[2] = jj_gen;
      ;
    }
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(COUNT);
    jj_consume_token(SEP);
    focusCount = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(TACKLE);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(EXPIRES);
    jj_consume_token(SEP);
    tackleExpires = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(SEP);
    jj_consume_token(OB);
    jj_consume_token(COUNT);
    jj_consume_token(SEP);
    tackleCount = jj_consume_token(NUM);
    jj_consume_token(CB);
    jj_consume_token(CB);
    VIEW_QUALITY iViewModeQual=VIEW_QUALITY.HIGH;
    VIEW_ANGLE iViewModeAngle=VIEW_ANGLE.NORMAL;
    TEAM iFocusTeam = ControllerNumbers.TEAM.UNCERTAIN;
    int iCycle = Integer.parseInt(cycle.image);
    double dStamina = Double.parseDouble(stamina.image);
    double dEffort = Double.parseDouble(effort.image);
    double dSpeed = Double.parseDouble(speed.image);
    double dSpeedDir = Double.parseDouble(speedDir.image);
    double dHeadAngle = Double.parseDouble(headAngle.image);
    int iKick = Integer.parseInt(kick.image);
    int iDash = Integer.parseInt(dash.image);
    int iTurn = Integer.parseInt(turn.image);
    int iSay = Integer.parseInt(say.image);
    int iTurnNeck = Integer.parseInt(turnNeck.image);
    int iCatch = Integer.parseInt(cat.image);
    int iMove = Integer.parseInt(move.image);
    int iChangeView = Integer.parseInt(changeView.image);
    int iArmMoveable = Integer.parseInt(armMoveable.image);
    int iArmExpires = Integer.parseInt(armExpires.image);
    double dArmDist = Double.parseDouble(armDist.image);
    double dArmDir = Double.parseDouble(armDir.image);
    int iArmCount = Integer.parseInt(armCount.image);
    int iFocusCount = Integer.parseInt(focusCount.image);
    int iTackleExpires = Integer.parseInt(tackleExpires.image);
    int iTackleCount = Integer.parseInt(tackleCount.image);
    switch(focusTeam.image.charAt(0)){
        case 'n':
                iFocusTeam=ControllerNumbers.TEAM.UNCERTAIN;
                break;
        case 'l':
                if(rc.isTeamEast())
                        iFocusTeam=ControllerNumbers.TEAM.OPPONENT;
                else
                        iFocusTeam=ControllerNumbers.TEAM.WE;
                break;
        case 'r':
                if(!rc.isTeamEast())
                        iFocusTeam=ControllerNumbers.TEAM.OPPONENT;
                else
                        iFocusTeam=ControllerNumbers.TEAM.WE;
                break;
    }
    switch(viewModeQual.image.charAt(0)){
      case 'h':
        iViewModeQual=ControllerNumbers.VIEW_QUALITY.HIGH;
        break;
      case 'l':
        iViewModeQual=ControllerNumbers.VIEW_QUALITY.LOW;
        break;
    }
    switch(viewModeAngle.image.charAt(1)){
      case 'i': iViewModeAngle=ControllerNumbers.VIEW_ANGLE.WIDE; break;
      case 'a': iViewModeAngle=ControllerNumbers.VIEW_ANGLE.NARROW; break;
      case 'o': iViewModeAngle=ControllerNumbers.VIEW_ANGLE.NORMAL; break;
    }

        // update sbi    
    sbi.setCycle(iCycle);
    sbi.setViewQuality(iViewModeQual);
    sbi.setViewWidth(iViewModeAngle);
    sbi.setStamina(dStamina);
    sbi.setEffort(dEffort);
    sbi.setSpeed(dSpeed);
    sbi.setSpeedDir(dSpeedDir);
    sbi.setNeckAngle(dHeadAngle);
    sbi.setCounter(Action.TYPE.KICK, iKick);
    sbi.setCounter(Action.TYPE.DASH, iDash);
    sbi.setCounter(Action.TYPE.TURN, iTurn);
    sbi.setCounter(Action.TYPE.SAY, iSay);
    sbi.setCounter(Action.TYPE.TURN_NECK, iTurnNeck);
    sbi.setCounter(Action.TYPE.CATCH_BALL, iCatch);
    sbi.setCounter(Action.TYPE.MOVE, iMove);
    sbi.setCounter(Action.TYPE.CHANGE_VIEW_MODE, iChangeView);
    sbi.setCounter(Action.TYPE.TACKLE, iTackleCount);
    sbi.setCounter(Action.TYPE.ATTENTIONTO, iFocusCount);
    sbi.setArmMoveable(iArmMoveable);
    sbi.setArmExpires(iArmExpires);
    sbi.setArmDist(dArmDist);
    sbi.setArmDir(dArmDir);
    sbi.setFocusTeam(iFocusTeam);
    sbi.setFocusNumber(iFocusNumber);
    sbi.setTackleExpires(iTackleExpires);
  }

  public SenseBodyParserTokenManager token_source;
  SimpleCharStream jj_input_stream;
  public Token token, jj_nt;
  private int jj_gen;
  final private int[] jj_la1 = new int[3];
  static private int[] jj_la1_0;
  static private int[] jj_la1_1;
  static {
      jj_la1_0();
      jj_la1_1();
   }
   private static void jj_la1_0() {
      jj_la1_0 = new int[] {0xc0,0x700,0x80000000,};
   }
   private static void jj_la1_1() {
      jj_la1_1 = new int[] {0x0,0x0,0x0,};
   }

  public SenseBodyParser(java.io.InputStream stream) {
     this(stream, null);
  }
  public SenseBodyParser(java.io.InputStream stream, String encoding) {
    try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
    token_source = new SenseBodyParserTokenManager(jj_input_stream);
    token = new Token();
    token.next = jj_nt = token_source.getNextToken();
    jj_gen = 0;
    for (int i = 0; i < 3; i++) jj_la1[i] = -1;
  }

  public void ReInit(java.io.InputStream stream) {
     ReInit(stream);
  }
  public void ReInit(java.io.InputStream stream, String encoding) {
    try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
    token_source.ReInit(jj_input_stream);
    token = new Token();
    token.next = jj_nt = token_source.getNextToken();
    jj_gen = 0;
    for (int i = 0; i < 3; i++) jj_la1[i] = -1;
  }

  public SenseBodyParser(java.io.Reader stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new SenseBodyParserTokenManager(jj_input_stream);
    token = new Token();
    token.next = jj_nt = token_source.getNextToken();
    jj_gen = 0;
    for (int i = 0; i < 3; i++) jj_la1[i] = -1;
  }

  public void ReInit(java.io.Reader stream) {
    jj_input_stream.ReInit(stream, 1, 1);
    token_source.ReInit(jj_input_stream);
    token = new Token();
    token.next = jj_nt = token_source.getNextToken();
    jj_gen = 0;
    for (int i = 0; i < 3; i++) jj_la1[i] = -1;
  }

  public SenseBodyParser(SenseBodyParserTokenManager tm) {
    token_source = tm;
    token = new Token();
    token.next = jj_nt = token_source.getNextToken();
    jj_gen = 0;
    for (int i = 0; i < 3; i++) jj_la1[i] = -1;
  }

  public void ReInit(SenseBodyParserTokenManager tm) {
    token_source = tm;
    token = new Token();
    token.next = jj_nt = token_source.getNextToken();
    jj_gen = 0;
    for (int i = 0; i < 3; i++) jj_la1[i] = -1;
  }

  final private Token jj_consume_token(int kind) throws ParseException {
    Token oldToken = token;
    if ((token = jj_nt).next != null) jj_nt = jj_nt.next;
    else jj_nt = jj_nt.next = token_source.getNextToken();
    if (token.kind == kind) {
      jj_gen++;
      return token;
    }
    jj_nt = token;
    token = oldToken;
    jj_kind = kind;
    throw generateParseException();
  }

  final public Token getNextToken() {
    if ((token = jj_nt).next != null) jj_nt = jj_nt.next;
    else jj_nt = jj_nt.next = token_source.getNextToken();
    jj_gen++;
    return token;
  }

  final public Token getToken(int index) {
    Token t = token;
    for (int i = 0; i < index; i++) {
      if (t.next != null) t = t.next;
      else t = t.next = token_source.getNextToken();
    }
    return t;
  }

  private java.util.Vector jj_expentries = new java.util.Vector();
  private int[] jj_expentry;
  private int jj_kind = -1;

  public ParseException generateParseException() {
    jj_expentries.removeAllElements();
    boolean[] la1tokens = new boolean[33];
    for (int i = 0; i < 33; i++) {
      la1tokens[i] = false;
    }
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 3; i++) {
      if (jj_la1[i] == jj_gen) {
        for (int j = 0; j < 32; j++) {
          if ((jj_la1_0[i] & (1<<j)) != 0) {
            la1tokens[j] = true;
          }
          if ((jj_la1_1[i] & (1<<j)) != 0) {
            la1tokens[32+j] = true;
          }
        }
      }
    }
    for (int i = 0; i < 33; i++) {
      if (la1tokens[i]) {
        jj_expentry = new int[1];
        jj_expentry[0] = i;
        jj_expentries.addElement(jj_expentry);
      }
    }
    int[][] exptokseq = new int[jj_expentries.size()][];
    for (int i = 0; i < jj_expentries.size(); i++) {
      exptokseq[i] = (int[])jj_expentries.elementAt(i);
    }
    return new ParseException(token, exptokseq, tokenImage);
  }

  final public void enable_tracing() {
  }

  final public void disable_tracing() {
  }

}
